<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background-color: red;
            margin: 20px;
            color: #fff;
        }
        div#bottom{
            width: 200px;
            height: 200px;
            background-color: blue;
        }
    </style>
    <script>
        window.onload=function(){
           var top=document.getElementById('top');
           var bottom=document.getElementById('bottom');
           top.ondragstart=function(event){
               //数据传输
               var data=event.dataTransfer;
               //传送id
               data.setData('text',this.id)
           }
           bottom.ondragover=function(event){
               event.preventDefault();
           }
           bottom.ondrop=function(event){
            //阻止页面默认打开   
            event.preventDefault();
            event.stopImmediatePropagation();
            //数据传输
            var data=event.dataTransfer;
            var id=data.getData('text');
            var top=document.getElementById(id);
            var topText=top.innerHTML;
            var bottomText=this.innerHTML;
            //将bottom的值给top
            top.innerHTML=bottomText;
            //将top的值给bottom
            this.innerHTML=topText;
           }
        }
    </script>
</head>
<body>
   <div id="top" draggable="true">
       <h1>hello</h1>
   </div>
   <div id="bottom">
       <h1>world</h1>
   </div>
</body>
</html>